//
//  YRJAboutSystemViewController.m
//  YanRenjie
//
//  Created by dllo on 15/11/6.
//  Copyright (c) 2015年 yanrenjie. All rights reserved.
//

#import "YRJAboutSystemViewController.h"
#import "YRJTripHeader.h"
#import <MessageUI/MessageUI.h>

@interface YRJAboutSystemViewController ()<MFMailComposeViewControllerDelegate>
@property(nonatomic, retain)UILabel *aboutVersionLabel;
@property(nonatomic, retain)UILabel *versionInfoDetailLabel;
@property(nonatomic, retain)UILabel *funtionLabel;
@property(nonatomic, retain)UILabel *funtionDetailLabel;
@property(nonatomic, retain)UIButton *helpAndFeedbackButton; // 帮助和反馈
@property(nonatomic, retain)UIScrollView *scrollView;

@end

@implementation YRJAboutSystemViewController
- (void)dealloc {
    [_aboutVersionLabel release];
    [_versionInfoDetailLabel release];
    [_funtionDetailLabel release];
    [_funtionLabel release];
    [_helpAndFeedbackButton release];
    [_scrollView release];
    
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"关于系统";
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets = 0;
    
    NSString *systemVersion = [[UIDevice currentDevice] systemVersion];//系统版本
    NSString *systemModel = [[UIDevice currentDevice] model];//是iphone 还是 ipad
    NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];//获取info－plist
    NSString *appName = [dic objectForKey:@"CFBundleIdentifier"];//获取Bundle identifier
    NSString *appVersion = [dic valueForKey:@"CFBundleVersion"];//获取Bundle Version
    NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
                              systemVersion, @"systemVersion",
                              systemModel, @"systemModel",
                              appName, @"appName",
                              appVersion, @"appVersion",nil];
    NSLog(@"%@", userInfo);
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:self.scrollView];
    [_scrollView release];
    
    
    self.aboutVersionLabel = [[UILabel alloc] initWithFrame:CGRectMake((30.0 / 375) * WIDTH, (20.0 / 667) * HEIGHT, (100.0 / 375) * WIDTH, (30.0 / 667) * HEIGHT)];
    [self.scrollView addSubview:self.aboutVersionLabel];
    [_aboutVersionLabel release];
    self.aboutVersionLabel.text = @"关于系统";
    
    self.versionInfoDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake((30.0 / 375) * WIDTH, (55.0 / 667) * HEIGHT, (335.0 / 375) * WIDTH, (30.0 / 667) * HEIGHT)];
    [self.scrollView addSubview:self.versionInfoDetailLabel];
    [_versionInfoDetailLabel release];
    self.versionInfoDetailLabel.font = [UIFont systemFontOfSize:16 * (SWIDTH / 375)];
    self.versionInfoDetailLabel.text = [NSString stringWithFormat:@"%@%@.0", @"系统版本:", userInfo[@"appVersion"]];
    
    self.funtionLabel = [[UILabel alloc] initWithFrame:CGRectMake((30.0 / 375) * WIDTH, (105.0 / 667) * HEIGHT, (100.0 / 375) * WIDTH, (30.0 / 667) * HEIGHT)];
    [self.scrollView addSubview:self.funtionLabel];
    [_funtionLabel release];
    self.funtionLabel.text = @"系统功能";
    
    self.funtionDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake((30.0 / 375) * WIDTH, (145.0 / 667) * HEIGHT, (335.0 / 375) * WIDTH, (30.0 / 667) * HEIGHT)];
    self.funtionDetailLabel.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.funtionDetailLabel];
    self.funtionDetailLabel.font = [UIFont systemFontOfSize:16 * (SWIDTH / 375)];
    [_funtionDetailLabel release];
    self.funtionDetailLabel.text = @"热门推荐:点击发现下一站可以查看所有的推荐, 再点击可以查看详细情况,折扣你先抢:主要是国内的所有打折的地方.点击查看全部可看所有的打折扣之地. 再点击可以查看详情,最后是热门游记, 点击可以查看详情.点击搜索可以搜索热门国家已经随便搜索, 可以看搜索的目的地, 相关的帖子, 折扣, 用户等.点击可以看情况.目的地:主要分为热门景点, 世界七大洲,以及港澳台等.点击进去可以对应国家或者城市的热门景点已经折扣等地.还可以点击收藏国家或者城市.秀一秀:可以看驴友们分享的旅游的情况, 点击可以看详情.个人中心:包括分享, 清除缓存, 查看我的收藏, 夜间模式, 以及关于系统等相关信息.";
    self.funtionDetailLabel.numberOfLines = 0;
    [self.funtionDetailLabel sizeToFit];
    
//    self.helpAndFeedbackButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    self.helpAndFeedbackButton.frame = CGRectMake((30.0 / 375) * WIDTH, (195.0 / 667) * HEIGHT, (100.0 / 375) * WIDTH, (250 + self.funtionDetailLabel.frame.size.height) / 667.0 * HEIGHT);
//    [self.scrollView addSubview:self.helpAndFeedbackButton];
//    [self.helpAndFeedbackButton setTitle:@"帮助和反馈" forState:UIControlStateNormal];
//    [self.helpAndFeedbackButton addTarget:self action:@selector(helpAndFeedbackAction:) forControlEvents:UIControlEventTouchUpInside];
//    self.scrollView.contentSize  = CGSizeMake(0, HEIGHT);
}

#pragma mark - button 点击方法的实现
- (void)helpAndFeedbackAction:(UIButton *)button {
    Class mailClass = NSClassFromString(@"MFMailComposeViewController");
    if (mailClass) {
        if ([mailClass canSendMail]) {
            [self dispalyMailBox];
        } else {
            [self showMailBoxOneDevice];
        }
    }else {
        [self showMailBoxOneDevice];
    }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    NSString *message;
    switch (result) {
        case MFMailComposeResultCancelled:
            message = @"取消发送";
            NSLog(@"%@", message);
            break;
        case MFMailComposeResultSaved:
            message = @"保存草稿";
            NSLog(@"%@", message);
            break;
        case MFMailComposeResultSent:
            message = @"已发送";
            NSLog(@"%@", message);
            break;
        case MFMailComposeResultFailed:
            message = @"发送失败";
            NSLog(@"%@", message);
            break;
            
        default:
            break;
    }
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


// 打开设备自带啊的邮件工具
- (void)showMailBoxOneDevice {
    NSString *mail = @"1282000376@qq.com";
    mail = [mail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mail]];
    
    
}


- (void)dispalyMailBox {
    
    //创建邮箱的视图Vc
    MFMailComposeViewController *mailBox = [[MFMailComposeViewController alloc]init];
    // 接收人地址
    NSArray *arr = [NSArray arrayWithObjects:nil];
    [mailBox setToRecipients:arr];
    // 主题填写
    [mailBox setSubject:@"意见反馈"];
    
    NSString *messageBody = @"邮箱反馈";
    [mailBox  setMessageBody:messageBody isHTML:YES];
//    //添加一个文件
//    UIImage *image = [UIImage imageNamed:@"yindaoye0.png"];
//    NSData *data = UIImagePNGRepresentation(image);
//    [mailBox addAttachmentData:data mimeType:@"" fileName:@"beautiful.jpg"];
    // 代理人
    mailBox.mailComposeDelegate = self;
    
    //模态
    [self presentViewController:mailBox animated:YES completion:^{
        
        
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
